import 'package:flutter/material.dart';

void main() {
  runApp(const MaterialApp(home: Main()));
}

class Main extends StatefulWidget {
  const Main({super.key});

  @override
  _MainState createState() {
    print('------createState------创建');
    return _MainState();
  }
}

class _MainState extends State<Main> {
  int age = 18;

  @override
  void initState(){
    print('------initState------初始化');
    super.initState();
  }

  @override
  void deactivate(){
    print('------deactivate------');
    super.deactivate();
  }
  
  @override
  Widget build(BuildContext context) {
    print('------build------');
    return Scaffold(
      appBar: AppBar(
        title: const Text(
          '有状态的组件',
        ),
        backgroundColor: Colors.amber,
      ),
      body: Center(
        child: Text('我今年$age岁了'),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () {
          setState(() {
            age++;
            debugPrint('点击了----$age');
          });
        },
        child: const Icon(Icons.add),
      ),
    );
  }
  
}
